﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;

namespace GenerateDataBaseLibrary
{


    public class ParametersStorageSection:ConfigurationSection
    {
        [ConfigurationProperty("cfgfilestorage")]
        public string CfgFileStorage 
        {
            get { var cfgfilestorage = (string)base["cfgfilestorage"]; return cfgfilestorage; }
            set { base["cfgfilestorage"] = value; }
        }
        [ConfigurationProperty("filestorage")]
        public string FileStorage 
        {
            get { var filestorage = (string)base["filestorage"]; return filestorage; }
            set { base["filestorage"] = value; }
        }
        [ConfigurationProperty("separator")]
        public char Separator
        {
            get { var separator = (char)base["separator"]; return separator; }
            set { base["separator"] = value; }
        }

    }
   
    /// <summary>
    /// This class represents the configuration section that holds
    /// the credentials within the configuration file
    /// </summary>
    public class SqlCredentialSection:ConfigurationSection 
    {
        [ConfigurationProperty("sqlcredential", IsRequired = true)]
        public SqlCredentialElement SqlCredential
        {
            get { var sqlcredential = (SqlCredentialElement)base["sqlcredential"]; return sqlcredential; }
            set { base["sqlcredential"] = value; }
        }
    }
    /// <summary>
    /// This class represent a given login when the sql server mode is activated
    /// </summary>
    public class SqlCredentialElement:ConfigurationElement
    {
        [ConfigurationProperty("username", IsRequired = true)]
        public string UserName
        {
            get { return (string)this["username"]; }
            set { this["username"] = value; }
        }
        [ConfigurationProperty("password", IsRequired = true)]
        public string Password
        {
            get { return (string)this["password"]; }
            set { this["password"] = value; }
        }

        protected override bool IsModified()
        {
            bool ret = base.IsModified();
            return ret;
        }


        protected override bool SerializeElement(System.Xml.XmlWriter writer, bool serializeCollectionKey)
        {
            bool ret = base.SerializeElement(writer, serializeCollectionKey);
            return ret;
        }
    }
    /// <summary>
    /// This class repesents the sql credentials or the login collection
    /// </summary>
    [ConfigurationCollection(typeof(SqlCredentialElement))]
    public class SqlCredentialElementCollection:ConfigurationElementCollection
    {
        public SqlCredentialElement this[int index]
        {
            get { return (SqlCredentialElement)BaseGet(index); }
            set { if (BaseGet(index) != null) { BaseRemoveAt(index); } BaseAdd(index, value); }
        }
       
        protected override object GetElementKey(ConfigurationElement element)
        {
            return ((SqlCredentialElement)element).GetHashCode();
        }

        protected override ConfigurationElement CreateNewElement()
        {
            return new SqlCredentialElement();
        }
    }
}
